package com.yd.redis_storage_client;

import com.yd.redis_storage_client.jedis.Jedis;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Jedis jedis = new Jedis("10.19.105.60",9600);

        // ds_set ds_get
        System.out.println(jedis.ds_set("existkey","testvalue"));
        System.out.println(jedis.ds_get("existkey"));
        System.out.println(jedis.ds_get("notexistkey"));

        // ds_exist
        System.out.println(jedis.ds_exists("existkey"));
        System.out.println(jedis.ds_exists("notexistkey","notexistkey2"));

        // ds_append
        System.out.println(jedis.ds_set("appendkey","welcome"));
        System.out.println(jedis.ds_append("appendkey"," somebody"));
        System.out.println(jedis.ds_get("appendkey"));

        // ds_incrby
        System.out.println(jedis.ds_set("incykey","0"));
        System.out.println(jedis.ds_incrby("incykey",1));
        System.out.println(jedis.ds_incrby("incykey",2));
        System.out.println(jedis.ds_get("incykey"));

        // ds_mset ds_gset
        System.out.println(jedis.ds_mset("name","test","sex","男"));
        System.out.println(jedis.ds_mget("name","sex","notexist"));

        // ds_del
        System.out.println(jedis.ds_set("test","test"));
        System.out.println(jedis.ds_set("test2","test2"));
        System.out.println(jedis.ds_get("test"));
        System.out.println(jedis.ds_get("test2"));
        System.out.println(jedis.ds_del("test","test2"));
        System.out.println(jedis.ds_mget("test","test2"));


        // ds_hset ds_hget
        System.out.println(jedis.ds_hset("hashkey","field1","value1"));
        System.out.println(jedis.ds_hget("hashkey","field1"));

        // ds_hexists
        System.out.println(jedis.ds_hexists("hashkey","field1","field2"));

        // ds_hincyby
        System.out.println(jedis.ds_hset("hashkey","incy","0"));
        System.out.println(jedis.ds_hincrby("hashkey","incy",1));
        System.out.println(jedis.ds_hincrby("hashkey","incy",3));
        System.out.println(jedis.ds_hget("hashkey","incy"));


        // ds_mset ds_mget
        System.out.println(jedis.ds_hmset("hashkey","field1","v1","field2","v2","field3","v3"));
        System.out.println(jedis.ds_hmget("hashkey","field1","field2","notexist"));

        // ds_hgetall
        System.out.println(jedis.ds_hgetAll("hashkey"));

        // ds_hdel
        System.out.println(jedis.ds_hdel("hashkey","field1","field2"));
        System.out.println(jedis.ds_hmget("hashkey","field1","field2","field3"));

        // ds_hlen
        System.out.println(jedis.ds_hlen("hashkey"));

        // ds_hvals
        System.out.println(jedis.ds_hvals("hashkey"));

        // ds_hsetnx
        System.out.println(jedis.ds_hsetnx("hashkey", "field4","v4"));

        // ds_hkeys_asc ds_hkeys_desc
        System.out.println(jedis.ds_hkeys_asc());
        System.out.println(jedis.ds_hkeys_asc("hashkey",10)); // 从hashkey 开始的10条
        System.out.println(jedis.ds_hkeys_asc(10));

        // ds_hkeys_count
        System.out.println(jedis.ds_hkeys_count("startkey","endkey"));

        // ds_keys_asc ds_keys_desc
        System.out.println(jedis.ds_keys_asc());
        System.out.println(jedis.ds_keys_asc("key",10));
        System.out.println(jedis.ds_keys_asc(10));

        // ds_keys_count
        System.out.println(jedis.ds_keys_count("startkey","endkey"));
        jedis.close();
    }
}
